package com.franklin.springbootdemo;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface SimpleMapper {

    @Select("<script>" +
            "select *" +
            "from smart_community_sky_plan_customer_order_layout_rel" +
            "<where>" +
            "<if test='keyword != null and keyword != \"\"'>" +
            "                AND (" +
            "                customer_name like concat('%',#{keyword,jdbcType=VARCHAR},'%')" +
            "                OR mobile like concat('%',#{keyword,jdbcType=VARCHAR},'%')" +
            "                OR tx_order_id like concat('%',#{keyword,jdbcType=VARCHAR},'%')" +
            "                )" +
            "            </if>" +
            "            <if test='designerId != null and designerId > 0'>" +
            "                AND designer_id = #{designerId,jdbcType=VARCHAR}" +
            "            </if>" +
            "</where>" +
            "        GROUP BY customer_id" +
            "</script>")
    String test();

    @Insert("<script>" +
            "INSERT INTO boss_account " +
            "<trim prefix='(' suffix=')' suffixOverrides=','>" +
            "<if test='bossId != null'>" +
            "boss_id," +
            "</if>" +
            "            <if test='nickName != null'>" +
            "                nick_name," +
            "            </if>" +
            "            <if test='account != null'>" +
            "                account," +
            "            </if>" +
            "            <if test='headUrl != null'>" +
            "                head_url," +
            "            </if>" +
            "            <if test='createBy != null'>" +
            "                create_by," +
            "            </if>" +
            "            <if test='createTime != null'>" +
            "                create_time," +
            "            </if>" +
            "            <if test='updateBy != null'>" +
            "                update_by," +
            "            </if>" +
            "            <if test='updateTime != null'>" +
            "                update_time," +
            "            </if>" +
            "            <if test='extraAttr != null'>" +
            "                extra_attr," +
            "            </if>" +
            "        </trim>" +
            "        <trim prefix=' VALUES(' suffix=')' suffixOverrides=','>" +
            "            <if test='bossId != null'>" +
            "                #{bossId,jdbcType=BIGINT}," +
            "            </if>" +
            "            <if test='nickName != null'>" +
            "                #{nickName,jdbcType=VARCHAR}," +
            "            </if>" +
            "            <if test='account != null'>" +
            "                #{account,jdbcType=VARCHAR}," +
            "            </if>" +
            "            <if test='headUrl != null'>" +
            "                #{headUrl,jdbcType=VARCHAR}," +
            "            </if>" +
            "            <if test='createBy != null'>" +
            "                #{createBy,jdbcType=VARCHAR}," +
            "            </if>" +
            "            <if test='createTime != null'>" +
            "                #{createTime,jdbcType=DATE}," +
            "            </if>" +
            "            <if test='updateBy != null'>" +
            "                #{updateBy,jdbcType=VARCHAR}," +
            "            </if>" +
            "            <if test='updateTime != null'>" +
            "                #{updateTime,jdbcType=DATE}," +
            "            </if>" +
            "            <if test='extraAttr != null'>" +
            "                #{extraAttr,jdbcType=VARCHAR}," +
            "            </if>" +
            "        </trim>" +
            "</script>"
    )
    int testInsert();

    @Select("<script>SELECT\n" +
            "\trr.id AS role_id,up.user_id,rr.role_name \n" +
            "FROM\n" +
            "\tsmart_community_model_room_user_permission up\n" +
            "\tLEFT JOIN smart_community_model_room_role rr ON up.role_id = rr.id \n" +
            "WHERE\n" +
            "\tuser_id IN " +
            "<foreach collection='userIdList' item='id' open='(' separator=',' close=')' index='index'>" +
            "#{id}" +
            "</foreach> AND up.app_id = #{appId}" +
            "</script>")
    List<Object> selectRoleListByUserIdByBatch(@Param("userIdList") Collection<Integer> userIdList, @Param("appId") Integer appId);

    Map<String,Object> getMap();
}
